

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_articles_latest
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;
$loai 		= $params->get('loai',	1);
$catid 		= $params->get('catid',  '');
if($loai==0){
?>
<ul class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) :  ?>
	<li>
		<a href="<?php echo $item->link; ?>">
			<?php echo $item->title; ?></a>
	</li>
<?php endforeach; ?>
</ul>

<?php
}

if($loai==1){
	$db = & JFactory::getDBO();
?>
<div class="ourporfolio">
    <h2 class="seo-h2"><strong><?php echo JText::_('Our Managed Properties'); ?></strong></h2>
    <div id="home-portfolio-list" class="clearfix">
        <div id="portfolio" class="portfolio-normal clearfix">
        <?php
	for($k=0;$k<count($catid);$k++){
	$sql="SELECT * from #__content where catid='".$catid[$k]."' and state=1";
	$db->setQuery($sql);
	$rows = $db->loadObjectList();
	
	//fitter menu id
	$wordfind = 'view=article';
	$sqlmenu="SELECT * from #__menu where link like '%$wordfind%' and published=1";
	$db->setQuery($sqlmenu);
	$rowitemidmenus = $db->loadObjectList();
	//fitter menu id
	
        for($i=0;$i<count($rows);$i++){
            $item = $rows[$i];
			
			//fitter menu id
			$Itemidmenu = "";
			for($m=0;$m<count($rowitemidmenus);$m++){
				$idarticle = $rowitemidmenus[$m]->link;
				$idarticle = explode('&id=',$idarticle);
				if($idarticle[1]==$item->id){$Itemidmenu = $rowitemidmenus[$m]->id;}
			}
			if($Itemidmenu!=""){
				$itemidneed = "&Itemid=".$Itemidmenu;
			}
			//fitter menu id
			
			$linkitem = 'index.php?option=com_content&view=article&id='.$item->id.':'.$item->alias.'&catid='.$item->catid.$itemidneed;
            $rowsimg	=	$item->images;
            $rowsimg	=	explode('","',$rowsimg);
            $rowsimg	=	explode('":"',$rowsimg[0]);
            $rowsimg	=	str_replace('\/','/',$rowsimg[1]);

            //Get the alt of the banner image
                $alt = $item->images;
                $alt = explode('","', $alt);
                $alt = explode('":"', $alt[2]); 
                $alt = $alt[1];

            //Mouse hover on porfolio
                $desc = '';
                $add = '';
                $tel = '';
                $fax = '';
                $web = '';
                $open_hour = '';
                $email = '';
                $social = '';       

                $info = $item->introtext;
                $info_array = explode('<li>', $info);

                $desc = $info_array[0];
               for ($J=1; $J < count($info_array) ; $J++) { 
                   if (stripos($info_array[1],JText::_('WMC_OUTLET_ADDRESS'))) {
                       $add = substr($info_array[1], strlen(JText::_('WMC_OUTLET_ADDRESS'))+6);
                       break;
                   }
               }
               for ($J=2; $J < count($info_array) ; $J++) { 
                   if (stripos($info_array[$J],JText::_('WMC_OUTLET_TEL'))) {
                       $tel = str_replace('<br />',JText::_('WMC_OUTLET_OR'),$info_array[$J]);
                       $tel = substr($tel,strlen(JText::_('WMC_OUTLET_TEL'))+6);
                       $tel = strip_tags($tel);
                       break;
                   }
               }
               for ($J=1; $J < count($info_array) ; $J++) { 
                   if (stripos($info_array[$J],JText::_('WMC_OUTLET_FAX'))) {
                       $fax = $info_array[$J];
                   }
               }
               for ($J=1; $J < count($info_array) ; $J++) { 
                   if (stripos($info_array[$J],JText::_('WMC_OUTLET_WEBSITE'))) {
                       $web = strip_tags($info_array[$J]);
                       $web = explode('WEBSITE', $web);
                       $web = $web[1];
                   }
               }
               for ($J=1; $J < count($info_array) ; $J++) { 
                   if (stripos($info_array[$J],JText::_('WMC_OUTLET_OPENING_HOURS'))) {                       
                       $open_hour = substr($info_array[$J],strlen(JText::_('WMC_OUTLET_OPENING_HOURS'))+6);
                       $open_hour = strip_tags($open_hour);
                       break;
                   }
               }
               for ($J=1; $J < count($info_array) ; $J++) { 
                   if (stripos($info_array[$J],JText::_('WMC_OUTLET_EMAIL'))) {
                       $email = $info_array[$J];
                   }
               }
               for ($J=1; $J < count($info_array) ; $J++) { 
                   if (stripos($info_array[$J],JText::_('WMC_OUTLET_SOCIAL'))) {
                       $social = $info_array[$J];
                   }
               }
        ?>
        <?php 
          // Set the path to the file
          $file = $rowsimg;

          // Instantiate our JImage object
          $image = new JImage($rowsimg);

          // Get the file's properties
          $properties = JImage::getImageFileProperties($file);

          // Resize the file as a new object
          $resizedImage = $image->resize(270, 220, true);

          // Determine the MIME of the original file to get the proper type for output
          $mime = $properties->mime;

          if ($mime == 'image/jpeg')
          {
              $type = IMAGETYPE_JPEG;
          }
          elseif ($mime = 'image/png')
          {
              $type = IMAGETYPE_PNG;
          }
          elseif ($mime = 'image/gif')
          {
              $type = IMAGETYPE_GIF;
          }

          $resizedImage->toFile($rowsimg.'_resize', $type);
        ?>

            <div class="portfolio-item">
                <div class="portfolio-image">
                    <a href="<?php echo $linkitem; ?>"><img alt="<?php echo $alt;?>" src="<?php echo $rowsimg.'_resize'; ?>" /><div class="item-overlay overlay-icon-pic"><span></span></div></a>
                </div>
                <div class="portfolio-desc"><h3><a href="<?php echo $linkitem; ?>"><?php echo $item->title; ?></a></h3></div>
                <div class="hover-detail-item">
                    <?php 
                        $image = json_decode($item->images);
                        $logo_outlet = htmlspecialchars($image->image_fulltext);
                     ?>
                    <div class="title-detail-item">
                        <?php echo $item->title; ?>
                    </div>
                    <div class="content-detail-item">
                        <div class="wraper-hover-item">
                          <div class="image"><img alt="<?php echo $alt;?>" src="<?php echo $logo_outlet; ?>" /></div>
                          <div class="descr"><?php echo $desc; ?></div>
                        </div>
                        
                        <div style="clear:both;"></div>
                        <!--  <?php echo strlen($desc) < 450 ? $desc : substr($desc,0,450).' ...' ?>   -->          
                        <table class="info">
                          <tr class="header">
                            <td><strong><?php echo JText::_('WMC_OUTLET_ADDRESS').':';?></strong></td>
                          </tr>
                          <tr>
                            <td><?php echo $add;?></td>
                          </tr>
                          <tr class="header">
                            <td><strong><p><?php echo JText::_('WMC_OUTLET_TEL').': </strong>'.$tel;?></p></td>
                          </tr>
                          <?php if($open_hour){?> 
                          <tr class="header">
                            <td><strong><p><?php echo JText::_('WMC_OUTLET_OPENING_HOURS').': </strong>'.$open_hour;?></p></td>
                          </tr>
                          <?php } ?>
                          <?php if($web){?> 
                          <tr class="header">
                            <td><strong><?php echo JText::_('WMC_OUTLET_WEBSITE') ; ?>:</strong><a target="_blank" href="//<?php echo $web;?>"><?php echo $web; ?></a></td>
                          </tr>
                          <?php } ?>
                        </table>
                    </div>
                </div>
            </div>

        <?php
        }
	}
        ?>
        </div>
        <div class="portfolio-navigation">
            <a href="#" id="home-portfolio-prev" class="portfolio-prev">Previous</a> 
            <a href="#" id="home-portfolio-next" class="portfolio-next">Next</a>
        </div>
        <div id="home-portfolio-pagination"></div>
        <script type="text/javascript">
        $("#portfolio").carouFredSel({
            circular:false,
            responsive:true,auto:false,
            items:{width:200,visible:{min:1,max:4}},
            scroll:{duration:900,easing:"easeOutExpo",wipe:true},
            prev:{button:"#home-portfolio-prev",key:"left"},
            next:{button:"#home-portfolio-next",key:"right"},
            pagination:"#home-portfolio-pagination"});
        </script>
    </div>
</div>
<?php
}
?>
